#include <stdio.h>
int cmp(char *x,char *y){
    while(*x==*y){
        x++;
        y++;
    }
    return *x>*y;
}
int main(){
    char str[100005];
    char *p=str;
    char *arr[105];
    int n,cnt=0;
    char t;
    scanf("%d",&n);
    t=getchar();
    for(int i=1;i<=n;i++){
        gets(p);
        arr[++cnt]=p;
        while(*p)p++;
        p++;
    }
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            if(cmp(arr[i],arr[j])){
                p=arr[i];
                arr[i]=arr[j];
                arr[j]=p;
            }
        }
    }
    for(int i=1;i<=n;i++){
        printf("%s\n",arr[i]);
    }
    return 0;
}